﻿using System.Data;
using IntelligentStorWpfApp.Interface;
using IntelligentStorWpfApp.Model;
using IntelligentStorWpfApp.Helper;
using MySql.Data.MySqlClient;

namespace IntelligentStorWpfApp.Services
{
    public class StatusServices : StatusInterface
    {
        string sqlStr = "";
        public bool Add(Status status)
        {
            sqlStr = "INSERT INTO c_status " +
               "(PositionId, StoreStatus) VALUES (@PositionId, @StoreStatus);";
            MySqlParameter[] paras =
            {
                new MySqlParameter ("@PositionId",status.PositionId),
                new MySqlParameter ("@StoreStatus",status.StoreStatus)
            };

            return DBHelper.ExecuteNonQuery(sqlStr, paras);
        }

        public bool Delete(int PositionId)
        {
            sqlStr = "delete from c_status where PositionId=@PositionId;";
            MySqlParameter[] paras =
             {
                new MySqlParameter ("@PositionId",PositionId)
            };
            return DBHelper.ExecuteNonQuery(sqlStr, paras);
        }

        public DataTable GetStatus(Status status)
        {
            sqlStr = "select * from c_status;";

            return DBHelper.ExecuteDataSet(sqlStr, null);
        }

        public bool UpdateStatus(Status status)
        {
            sqlStr = "Update  c_status set StoreStatus=@storeStatus where PositionId=@PositionId;";
            MySqlParameter[] paras =
             {
                new MySqlParameter ("@PositionId",status.PositionId),
                new MySqlParameter ("@StoreStatus",status.StoreStatus)
            };
            return DBHelper.ExecuteNonQuery(sqlStr, paras);
        }
    }
}
